#!/bin/bash


#归档函数 
function toBak(){
    dest=$1
    src=$2
    if [ -f $dest ];then
        echo;
        echo "备份文件已存在，归档失败……";
        echo;
        exit -1
    fi
    
    if [ ! -d $src ];then
        echo;
        echo "待备份目录不存在……";
        echo;
        exit -1
    fi

   echo 开始备份
   echo $dest
   echo $src
   echo 

   tar -cPf $dest $src

   if [ $? -ne 0 ];then
       echo
       echo "打包异常"
       exit -1
   fi
}

# 脚本正式开始
echo "正在停止所有服务 supervisor stop all"
supervisorctl stop all

sleep 3

if [ $? -ne 0 ];then
   echo
   echo "supervisor 服务停止异常"
   exit -1
fi


# 打包1
toBak ~/bak/MindSCADA.$DATE.tar ~/MindSCADA

# 打包2
toBak ~/bak/server.$DATE.tar ~/server


echo "打包完成"



# 启动所有服务
# supervisorctl start all



# 查找超过30天的备份文件
#find ~/bak -mtime +30 -name "*.tar" -exec rm -rf {} \;
